package com.suntront.lib_db.dao;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.suntront.lib_db.table.MeterT;
import com.suntront.lib_db.table.MeterTDownLoadUpdate;

import java.util.List;


/**
 *
 */
@Dao
public interface MeterDao {
    //插入多条数据
    @Insert()
    List<Long> insertMeters(List<MeterT> meterTs);

    @Query("SELECT * FROM MeterT Where AdminId = :AdminId")
    List<MeterT> queryMeterTsByAdminId(String AdminId);

    @Query("SELECT * FROM MeterT Where AdminId = :AdminId AND isLoad = :isLoad")
    List<MeterT> queryMeterTsByAdminIdIsLoad(String AdminId,boolean isLoad);

    @Query("SELECT * FROM MeterT Where AdminId = :AdminId AND rosterName LIKE :rosterName")
    List<MeterT> queryMeterTsByAdminIdAndRosterName(String AdminId, String rosterName);

    @Query("SELECT * FROM MeterT Where rosterId = :rosterId LIMIT 1")
    MeterT queryMeterTsById(int rosterId);

    @Query("SELECT * FROM MeterT Where rosterCode = :rosterCode LIMIT 1")
    MeterT queryMeterTsByCode(String rosterCode);

    @Update
    int updateMetes(List<MeterT> meterTs);

    @Query("UPDATE MeterT SET isUpdateOrder = :isUpdateOrder Where rosterId = :rosterId")
    int updateMetes(int rosterId,boolean isUpdateOrder);

    /**
     * 获取某人名下，未上传的册本
     *
     * @param AdminId
     * @return
     */
    @Query("SELECT * FROM MeterT Where AdminId = :AdminId AND unUpLoadCount > 0 ORDER BY id")
    List<MeterT> queryMeterTsByAdminIdNoUp(String AdminId);

    /**
     * 根据主键id 只更新数据库表中的部分字段
     *
     * @param meterTDownLoadUpdates
     */
    @Update(entity = MeterT.class)
    void updateMetesDownLoad(List<MeterTDownLoadUpdate> meterTDownLoadUpdates);

    @Query("DELETE FROM MeterT")
    void deleteAll();
}
